package com.ymdx.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 所有实体类的基类。
 * Created by yangliwei on 2017/7/9.
 */
@MappedSuperclass//这个声明只是一个标注，用来说明这个类的映射信息应用于从它继承的实体。
public abstract class IdEntity implements Serializable {
    private static final long serialVersionUID = -7554930201074113834L;


    protected Long id;//protected权限


    private Integer version = 0; //乐观锁，检测更新的时候是否有脏数据出现

    private Boolean valid = true;//逻辑删除

    private Date createTime = null;
    private Date modifyTime = new Date();
    private Date deleteTime = null;

    //声明最好放在get方法上面，要统一，不能一些放在get一些放在field上面
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    //这里不使用get 要不然每次初始化的version 将在beancopy到持久化对象里面去，导致查询出现锁失败
    //这里主要是屏蔽了 beanCopyUtils里面的get方法，但是框架貌似使用的反射比价吊，还是能获取version值
    @Version
    public Integer isVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Boolean getValid() {
        return valid;
    }

    public void setValid(Boolean valid) {
        this.valid = valid;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Date getDeleteTime() {
        return deleteTime;
    }

    public void setDeleteTime(Date deleteTime) {
        this.deleteTime = deleteTime;
    }
}
